package org.csu.mypetstore.tools;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class WebLog {

    public static void WriteWebLog(String msg) throws IOException {

        String path = "D:/Programs/JavaProjects/jpet-store/src/main/java/org/csu/mypetstore/tools/";//
        File file = new File(path + "WebLog.txt");
        //String current = df.format(System.currentTimeMillis());
        Date date = new Date();//获取当前的日期
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String str = df.format(date);//获取String类型的时间
        //System.out.println(str);


        if(!file.exists())
        {
            msg =  str + "\n" + msg + "\n";
            file.createNewFile();
        }else{
            msg = "\n" + str + "\n" + msg + "\n";
        }

        try {
            FileWriter writer = new FileWriter(file,true);
            writer.write(msg);
            writer.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
